{% extends 'admin/base.html' %}
{% block title %}管理员编辑{% endblock %}
{% block body %}
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header">管理员管理</div>
      <div class="layui-card-body" style="padding: 15px;">
        <form class="layui-form" action="" lay-filter="component-form-group">

        
          <div class="layui-form-item">
            <label class="layui-form-label">帐号</label>
            <div class="layui-input-block">
              <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入帐号" class="layui-input" value="{{info.name}}">
            </div>
          </div>

              <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
              <input type="text" name="pwd" lay-verify="required" autocomplete="off" placeholder="请输入密码" class="layui-input" value="{{info.pwd}}">
            </div>
          </div>
             


          <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
              <div class="layui-footer" style="left: 0;">
                <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
              </div>
            </div>
          </div><input name="id" type="hidden" value="{{info.id|default('0')}}" />

        </form>
      </div>
    </div>
  </div>

    
  <script src="/static/layui/layui.js"></script>
  <script>


  layui.config({
    base: '/static/layui/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form', 'laydate','upload'], function(){
    var $ = layui.$
    ,layer = layui.layer
    ,laydate = layui.laydate
    ,form = layui.form;
     parent=parent;
    form.render(null, 'component-form-group');

    laydate.render({
      elem: '#LAY-component-form-group-date'
    });
    
    /* 自定义验证规则 */
    form.verify({
      username: function(value){
        if(value.length < 3){
          return '帐号至少得3个字符啊';
        }
      },
	   password: function(value){
        if(value.length < 3){
          return '密码至少得3个字符啊';
        }
      }
     
      ,content: function(value){
        layedit.sync(editIndex);
      }
    });
    

    
    /* 监听提交 */
    form.on('submit(component-form-demo1)', function(data){
		var index = parent.layer.getFrameIndex(window.name);  //获取父类
		console.log('表单:'+JSON.stringify(data.field));
      

	  
	  $.post("{{get_url('admin.admin.save')}}",data.field,
              function(data){ 
			  
                if(data.code==200){
                    parent.layer.alert(data.msg, {closeBtn: 0}, function(){
                        parent.layer.close(index);
                        parent.window.location.reload()
                  });
                }else{
                  layer.alert(data.msg);
                }

			
			  }
		);
	  
      return false;
    });
  });
  </script>

{% endblock %}